import { Body, Controller, Get, Param, Post, Put, Query } from '@nestjs/common';
import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger';
import { JobService } from './job.service';
import { CreateJobDto, FindJobDto, SearchJobDto, UpdateJobDto } from './job.dto';

@ApiTags('岗位管理')
@ApiBearerAuth()
@Controller('job')
export class JobController {
  constructor(private jobService: JobService) {}

  @Get('list')
  @ApiOperation({ summary: '获取全部岗位列表' })
  async getJobList(@Query() query: FindJobDto) {
    return await this.jobService.find(query);
  }

  @Get('company/list/:id')
  @ApiOperation({ summary: '获取公司岗位列表' })
  async getCompanyJobList(@Param('id') id: string) {
    return this.jobService.findJobsByCompanyId(+id);
  }

  @Get('detail/:id')
  @ApiOperation({ summary: '获取岗位详情' })
  async getJobInfo(@Param('id') id: string) {
    return this.jobService.findOne(+id);
  }

  @Get('info/detail/:id')
  @ApiOperation({ summary: '获取岗位详情' })
  async getJobInfoDetail(@Param('id') id: string) {
    return this.jobService.jobInfo(+id);
  }

  @Post('create')
  @ApiOperation({ summary: '添加岗位' })
  async createJob(@Body() createJobDto: CreateJobDto) {
    return this.jobService.create(createJobDto);
  }

  @Put('update')
  @ApiOperation({ summary: '更新岗位' })
  async updateJob(@Body() updateJobDto: UpdateJobDto) {
    return this.jobService.update(updateJobDto);
  }

  @Post('search')
  @ApiOperation({ summary: '搜索岗位' })
  async searchJob(@Body() query: SearchJobDto) {
    return await this.jobService.search(query);
  }
}
